import { Tagslist,getpush ,Navtitlelist,classpush} from '@/api/index';
import { message } from 'antd';

export default {
  namespace: 'Biao',
  state: {
    //文章分类
    list: [],
    classlist:[]
  },

  //同步方法
  reducers: {
    //获取文章分类
    setlist(state: any, action: any) {

      state.list = action.payload;
      console.log( state.list);

      return {
        ...state,
        ...action.payload,
      };
    },
    setclasslist(state: any, action: any) {

      state.classlist = action.payload;
      console.log( state.list);

      return {
        ...state,
        ...action.payload,
      };
    },
    setpush(state:any, action:any) {
      console.log(action)
      return {
        ...state,
        ...action.payload,
      };
    },
    classpush(state:any, action:any) {
      console.log(action)
      return {
        ...state,
        ...action.payload,
      };
    },
  },
  //异步方法
  effects: {
    //获取文章分类数据
    *getlist({ payload }: any, { call, put }: any): any {
      //获取接口数据
      let result: any = yield call(Tagslist, payload);
      yield put({
        type: 'setlist',
        payload: result.data.data,
      });
    },
    *getclasslist({ payload }: any, { call, put }: any): any {
      //获取接口数据
      let result: any = yield call(Navtitlelist, payload);
      yield put({
        type: 'setclasslist',
        payload: result.data.data,
      });
    },
    *Biaopush({payload}:any,{call,put}:any):any{
      console.log(payload,'0000000000000000000000');

     const result=yield call(getpush,payload)
     console.log(result);

     yield put({
       type:"setpush",
       payload:result.data.data
     })
     if(result.status===201){
       message.success('保存成功')
     }
   },
    *getpush({payload}:any,{call,put}:any):any{
      console.log(payload,'0000000000000000000000');

     const result=yield call(classpush,payload)

     yield put({
       type:"classpush",
       payload:result.data.data
     })
     if(result.status===201){
       message.success('保存成功')
     }
   }

  },
};
